import presetWeapp from 'unocss-preset-weapp'
import { extractorAttributify, transformerClass } from 'unocss-preset-weapp/transformer'
import { defineConfig } from 'unocss'
// 适配微信小程序的transformRules
const transformRules = {
  '.': '-d111-',
  '/': '-s111-',
  ':': '-c111-',
  '%': '-p111-',
  '!': '-e111-',
  '#': '-w111-',
  '(': '-b111l-',
  ')': '-b111r-',
  '[': '-f111l-',
  ']': '-f111r-',
  '$': '-r111-',
  ',': '-r222-',
}

const { presetWeappAttributify, transformerAttributify } = extractorAttributify({
  transformRules
})

export default defineConfig({
  // 自定义内容短语
  shortcuts: [
    {
      'flex-center':'flex items-center justify-center',

      'absolute-rb': 'absolute right-0 bottom-0',
      'absolute-rt': 'absolute right-0 top-0',
      'absolute-lb': 'absolute left-0 bottom-0',
      'absolute-lt': 'absolute left-0 top-0',
      'absolute-fill': 'absolute left-0 top-0 bottom-0 right-0',
      'absolute-center': 'absolute left-50% top-50% -translate-x-50% -translate-y-50%',
      'absolute-x-center': 'absolute left-50% -translate-x-50%',
      'absolute-y-center': 'absolute top-50% -translate-y-50%',
      
      'fixed-rb': 'fixed right-0 bottom-0',
      'fixed-rt': 'fixed right-0 top-0',
      'fixed-lb': 'fixed left-0 bottom-0',
      'fixed-lt': 'fixed left-0 top-0',
      'fixed-fill': 'fixed left-0 top-0 bottom-0 right-0',
      'fixed-center': 'fixed left-50% top-50% -translate-x-50% -translate-y-50%',
      'fixed-x-center': 'fixed left-50% -translate-x-50%',
      'fixed-y-center': 'fixed top-50% -translate-y-50%',
    },
    [/^wh-(.*)$/,([, d]) => `w-${d} h-${d}`],
    [/^absolute-rb-(.*)$/,([, d]) => `absolute right-${d} bottom-${d}`],
    [/^absolute-rt-(.*)$/,([, d]) => `absolute right-${d} top-${d}`],
    [/^absolute-lb-(.*)$/,([, d]) => `absolute left-${d} bottom-${d}`],
    [/^absolute-lt-(.*)$/,([, d]) => `absolute left-${d} top-${d}`],
    [/^fixed-rb-(.*)$/,([, d]) => `fixed right-${d} bottom-${d}`],
    [/^fixed-rt-(.*)$/,([, d]) => `fixed right-${d} top-${d}`],
    [/^fixed-lb-(.*)$/,([, d]) => `fixed left-${d} bottom-${d}`],
    [/^fixed-lt-(.*)$/,([, d]) => `fixed left-${d} top-${d}`],
  ],
  // 自定义主题
  
  presets: [
    // https://github.com/MellowCo/unocss-preset-weapp
    presetWeapp({
      transformRules,
      whRpx: true,
    }),
    // attributify autocomplete
    presetWeappAttributify()
  ],
  transformers: [
    // options 见https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerAttributify
    transformerAttributify({
      transformRules,
    }),

    // options 见https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerClass
    transformerClass({
      transformRules,
    }),
  ],
  
})